Skip to content

Conversation

@mikhail-aws
Copy link
Contributor

@mikhail-aws mikhail-aws commented Nov 7, 2023

Note:

Add spec validations

  • Spec is invalid
  • TargetRef does not exists in k8s
  • Multiple targetRefs point to same resource

Add resource cleanup - delete previous policy - when spec is changed.
All these use-cases tested manually.

Code changes:

  • Move branching between ServiceNetwork and Service from Controller to Manager.
  • Remove unnecessary k8s updates. Right now call only once for Status (on upsert) and Spec updates.
  • Added some unit tests around controller

Leftovers:

  • Remove manager's test code due to refactoring, will add later.
  • When policy is in conflict and conflict is resolved need to trigger update for other policies, otherwise policy stays in conflict until other unrelated triggers happen

import "errors"

var (
TargetGroupNameErr = errors.New("wrong group name")
Copy link
Member

@xWink xWink Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Error message is generic among all groups, so why is the error variable specific to target groups?

var (
TargetGroupNameErr = errors.New("wrong group name")
TargetKindErr = errors.New("target kind error")
TargetRefNotExists = errors.New("targetRef does not exists")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: targetRef does not exist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will change names

IAMAuthPolicyAnnotation = "iam-auth-policy"
IAMAuthPolicyAnnotationResId = k8s.AnnotationPrefix + IAMAuthPolicyAnnotation + "-resource-id"
IAMAuthPolicyAnnotationType = k8s.AnnotationPrefix + IAMAuthPolicyAnnotation + "-resource-type"
IAMAuthPolicyFinalizer = k8s.AnnotationPrefix + IAMAuthPolicyAnnotation
Copy link
Member

@xWink xWink Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the typical finalizer format for CRD finalizers? We follow a different pattern in other controllers, like service.k8s.aws/resources and accesslogpolicy.k8s.aws/resources

Copy link
Member

@xWink xWink Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've read, finalizers are typically in the format of example.com/finalizer. This appears to be something we should change across all our resources, and have one finalizer for any resource type (which makes sense, since we have no reason to put the resource Kind in the finalizer for that kind, the purpose of the finalizer name is to avoid collisions with other controllers).

This is a non-blocker for the current PR, I'll make an issue to address it.

#479

controllerutil.RemoveFinalizer(k8sPolicy, authPolicyFinalizer)
func (c *IAMAuthPolicyController) reconcileDelete(ctx context.Context, k8sPolicy *anv1alpha1.IAMAuthPolicy) (ctrl.Result, error) {
err := c.validateSpec(ctx, k8sPolicy)
if err == nil {
Copy link
Member

@xWink xWink Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if err != nil?

Copy link
Contributor Author

@mikhail-aws mikhail-aws Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore validation errors on deletion

Copy link
Member

@xWink xWink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments, can be addressed later. Liking the new utility functions, will be nice QoL improvements for other reconcilers.

return model.IAMAuthPolicyStatus{}, err
}
resourceId := *svc.Id
err = m.enableSvcIAMAuth(ctx, resourceId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand it correctly from our previous standup meeting, for this issue: #467

When create the AuthPolicy, the order should be: (not correct in current PR)

  1. PutAuthPolicy
  2. Change AuthType to AWS_IAM

When create the AuthPolicy, the order should be: (correct in current PR)

  1. Change AuthType to NONE
  2. DeleteAuthPolicy

Do you need to change creation handling order?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to put policy we first enable iam and then put policy, for delete we disable iam and remove policy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohakkohli Could you help to double confirm?

@mikhail-aws mikhail-aws merged commit 873e926 into aws:main Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants